<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <style>
        *{
            margin: 0;padding: 0;
        }
        .main{
            overflow: hidden;
        }
        .item{
            padding: 10px;
            border: 1px solid #666;
            float: left;
        }
        img{
            width: 200px;
        }
    </style>
</head>
<body>
    <div class="main"></div>
    <script>
        var url = "http://47.113.104.50:8000/more"

        function http(url){
            return new Promise((resolve,reject)=>{
                $.ajax({
                    method:"get",
                    url,
                    success:res=>resolve(res)
                })
            })
        }
        function dealData(res){
            res.forEach(item=>{
                var html = `
                            <div class="item">
                                <img src=${item.imageUrl} alt="">
                            </div>
                        `
                $(".main").append(html)
            })
        }
        function position(){
            var ww = $(window).width();
            var box = $(".item").outerWidth();
            var num = Math.floor(ww/box);
            var arr=[];
            // console.log(num);
            $(".item").each((index,item)=>{
                // console.log(index);
                if(index<num){
                    arr.push($(item).outerHeight());
                    console.log(arr);
                }else{
                    var minHeight = Math.min(...arr);
                    var minIndex = arr.indexOf(minHeight);
                    var offsetLeft = $(".item").eq(minIndex).offset().left;
                    $(item).css({position:"absolute",left:offsetLeft,top:minHeight});
                    arr[minIndex] = minHeight+$(item).outerHeight();
                }
            })
        }

        async function go(url){
            var res = await http(url);
            dealData(res);
            setTimeout(position,100);
        }
        go(url);

    </script>
</body>
</html>